package com.taint.configuration;

import com.taint.sourcesink.MethodHook;
import org.yaml.snakeyaml.Yaml;
import java.io.*;
import java.util.ArrayList;
import java.util.Map;


import static com.taint.agent.FlowTaintAgent.methodSinkHookMap;
import static com.taint.agent.FlowTaintAgent.methodSourceHookMap;

public class Configuration {



    public static Map LoadYaml()  {

        InputStream in=Configuration.class.getResourceAsStream("/methods.yaml");

        Map conf =new Yaml().load(in);

        try {
            in.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return conf;

    }

    public static void LoadYaml(String yamlpath)  {

        try {
            FileInputStream inputStream=new FileInputStream(yamlpath);
            Map conf =new Yaml().load(inputStream);

            ArrayList  sinks= (ArrayList) conf.get("sinks");
            //System.out.println(FlowTaintAgent.getMethodSinkHookMap());
            ArrayList  sources = (ArrayList) conf.get("sources");
            //System.out.println("test: "+methodSinkHookMap.size());
            MethodHook.InsertClazz(sinks,methodSinkHookMap);
            MethodHook.InsertClazz(sources,methodSourceHookMap);
            //System.out.println("test: "+methodSinkHookMap.size());

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }

    }

}
